package com.yoomiito.app.adapter.home.reommend;

import android.content.Context;
import androidx.annotation.NonNull;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.LayoutHelper;
import com.yoomiito.app.R;
import com.yoomiito.app.model.bean.HotGoodsInfo;

import java.util.List;

/**
 * 首页----VIP
 */
public class HomeBaoPinAdapter extends DelegateAdapter.Adapter<RecyclerView.ViewHolder> {

    private Context mContext;
    private LayoutHelper mLayoutHelper;
    private RecyclerView.RecycledViewPool viewPool;
    private HomeBaoPinItemAdapter homeBaoPinItemAdapter;
    private List<HotGoodsInfo> mBaoPinGoods;
    private HomeBaoPinItemAdapter.OnItemClickListener mOnItemClickListener;
    public HomeBaoPinAdapter(Context context, LayoutHelper layoutHelper , RecyclerView.RecycledViewPool viewPool,HomeBaoPinItemAdapter.OnItemClickListener mOnItemClickListener) {
        mContext = context;
        mLayoutHelper = layoutHelper;
        this.viewPool = viewPool;
        this.mOnItemClickListener = mOnItemClickListener;
    }

    @Override
    public LayoutHelper onCreateLayoutHelper() {
        return mLayoutHelper;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_baopin, parent, false);
        return new ItemViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        ItemViewHolder viewHolder = (ItemViewHolder) holder;
        viewHolder.iv.setOnClickListener(v -> mOnItemClickListener.onClick(-1,true));
//        if(UserInfoConfig.getCompanyId() ==1){//默认瑰蜜汇
//            viewHolder.iv.setImageResource(R.drawable.ym_bg);
//            viewHolder.rcy.setBackgroundResource(R.drawable.bg_ym_color);
//        }
        viewHolder.rcy.setRecycledViewPool(viewPool);
        LinearLayoutManager layoutManager = new LinearLayoutManager(mContext);
        layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        viewHolder.rcy.setLayoutManager(layoutManager);
        homeBaoPinItemAdapter = new HomeBaoPinItemAdapter(mContext, mBaoPinGoods);
        viewHolder.rcy.setAdapter(homeBaoPinItemAdapter);
        homeBaoPinItemAdapter.setOnItemClickListener(mOnItemClickListener);
    }

    public void setData(List<HotGoodsInfo> goodsInfos){
        if (goodsInfos==null)return;
        this.mBaoPinGoods = goodsInfos;
        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        return 1;
    }

    @Override
    public int getItemViewType(int position) {
        return 3;
    }

    private class ItemViewHolder extends RecyclerView.ViewHolder {

        private RecyclerView rcy;
        private ImageView iv;

        public ItemViewHolder(View itemView) {
            super(itemView);
            iv = itemView.findViewById(R.id.item_baopin_iv);
            rcy = itemView.findViewById(R.id.item_baopin_rcy);
        }
    }
}
